<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="m" uri="http://localhost:8080/cxy"%>
<%@ include file="base.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>${issues.title }</title>
		<link href="${basePath }/styles/style.css" rel="stylesheet" type="text/css" />
		<link href="${basePath }/scripts/easy_validator/css/validate.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript" src="${basePath}/scripts/jquery.js"></script>
		<script type="text/javascript" src="${basePath }/scripts/easy_validator/js/easy_validator.js"></script>
		<script type="text/javascript" src="${basePath }/scripts/easy_validator/js/jquery.bgiframe.min.js"></script>
	</head>

	<body>
		<%@ include file="header.jsp"%>
		<%@ include file="secondary-bar.jsp"%>
		<%@ include file="sidebar.jsp"%>
		<div id="main">
			<div class="column">
				<div class="module_content">
					<div id="feed_box">
						<div class="issues_items">
							<h3 class="issues_title">
								${issues.title }
							</h3>
							<div class="talk_item">
								<span class="by">By</span>
								<a href="user!get.jspx?id=${issues.createUser.id }">${issues.createUser.userName
									}</a>
								<span class="date">${issues.createTime }</span>
								<span class="talk_content">${issues.content }</span>
							</div>
						</div>
						<div class="issues_items">
							<h3 class="issues_title">
								当前讨论
							</h3>
							<c:forEach items="${issues.talkSet }" var="t">
								<div class="talk_item">
								<span class="by">By</span>
								<a href="user!get.jspx?id=${t.user.id }">${t.user.userName }</a>
								<span class="date">${t.createTime }</span>
								<span class="talk_content">${t.content }</span>
							</div>
							</c:forEach>							
							<hr />
							<textarea class="textarea_style" id="content"  tip="不能为空" reg="^.+$"></textarea>
							<input type="button" class="btn_talk" value="参与讨论" />
						</div>
					</div>
					<script type="text/javascript">
						$(document).ready(function() {
							setInterval(function(){
								var v = $("#content").val();								
								$.getJSON("talk!ajaxFind.jspx",{"issuesId":"${issues.id}"},function(json){
									$(json).each(function(){
										var str = "<div class='talk_item'>";
										str += "<span class='by'>By</span>";
										str += "<a href='user!get.jspx?id=${sessionScope.currUser.id}'> ${sessionScope.currUser.userName}</a>";
										str += "<span class='date'>"+ this.createTime + "</span>";
										str += "<span class='talk_content'>" + this.content + "<span>";
										str += "</div>";
										$(str).insertAfter(".talk_item:last");
									});
								});
							},5000);
							$(".btn_talk").click(function() {
								var v = $("#content").val();
								$.getJSON("talk!ajaxAdd.jspx",{"content":v,"issuesId":"${issues.id}"},function(json){
									var str = "<div class='talk_item'>";
									str += "<span class='by'>By</span>";
									str += "<a href='user!get.jspx?id=${sessionScope.currUser.id}'> ${sessionScope.currUser.userName}</a>";
									str += "<span class='date'>" + json.createTime + "</span>";
									str += "<span class='talk_content'>" + json.content + "<span>";
									str += "</div>";
									$(str).insertAfter(".talk_item:last");
								});
							});
							$("#btn_changeuser").click(function(){
								var v = $("#workuser").val();
								$.post("issues!update.jspx",{"issues.workUser.id":v,"issues.id":"${issues.id}"},function(){
									$("#workUserName").html($("#workuser option:selected").html());
									$("#tipinfo").html("已分配给");
									alert("更新成功！");
								});
							});
							/*
							$("#btn_changestate").click(function(){
								var v = $("#all_state").val();
								$.post("issues!updateState.jspx",{"issues.state":v,"issues.id":"${issues.id}"},function(){
									$("#currState").html($("#all_state option:selected").val());
									alert("更新成功！");
								});
							});
							*/
						});
					</script>
					<div class="my_activity">
						<h3 class="mytask">
							当前状态：
							<span id="currState" class="state">${issues.state }</span>
						</h3>
						<form name="state_form" action="issues!updateState.jspx" method="post">
							<input type="hidden" name="issues.id" value="${issues.id}"/>
							<div class="issue_item">
								<m:issues_state state="${issues.state}" name="issues.state"/>
								<input type="submit" id="btn_changestate" value="更改" />
							</div>
						</form>
					</div>
					<div class="my_activity">
						<h3 class="mytask">
							<c:choose>
								<c:when test="${issues.workUser.id ne 0}">
									<span id="tipinfo">已分配给：</span>
									<span id="workUserName" class="state">${issues.workUser.userName }</span>
								</c:when>
								<c:when test="${issues.workUser.id eq 0}">
									<span id="tipinfo">该任务目前还未分配：</span>
									<span id="workUserName" class="state">请分配</span>
								</c:when>
							</c:choose>
						</h3>
						<div class="issue_item">
							<select id="workuser" class="all_state">
								<c:forEach items="${issues.project.userSet }" var="u">
									<option value="${u.id }">
										${u.userName }
									</option>
								</c:forEach>								
							</select>
							<input type="button" id="btn_changeuser" value="更改" />
						</div>
					</div>
				</div>
			</div>
		</div>
	</body>
</html>
